Repository navigation
fix: boykov_kolmogorov_max_flow color map with several edges to the sink - #656
Merged
Merged
Conversation
BayKeremm
force-pushed
the
fix-bk-color-map
branch
from
October 21, 2026 10:39
02efd8b to
06d6d66
Compare
|
Boost dependency footprint vs Header-inclusion weights (graph files pulling each direct dependency in): No header-inclusion-weight changes. Transitive Boost modules: 47 → 47 (0) |
|
Compiler-warning counts vs
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
…sink The color map should describe a minimum cut: the black vertices are the source side, and the edges from them to the others carry exactly the flow. Two small graphs in which vertex 1 has two edges to the sink break it: the flow is right, but vertex 1 is left gray although the source still reaches it. The random graph of test_adjacency_list_vecS breaks it too, so that test now checks the cut as well. This fails until the fix that follows. Refs boostorg#655
augment_direct_paths() looked up only a vertex's first edge to the sink when it put the vertex in the source tree, then moved every vertex with residual capacity left to the sink into the sink tree, whatever its tree. A vertex with a second edge to the sink was moved, left gray once that edge was saturated, and never reached again from the source, which is not an active vertex. The flow was still maximal, but the color map was not a minimum cut. A vertex already in the source tree now stays there: it is active, so grow() finds its remaining edges to the sink. Fixes boostorg#655
BayKeremm
force-pushed
the
fix-bk-color-map
branch
from
October 26, 2026 09:32
3d9d414 to
f954df8
Compare
Becheler
approved these changes
Oct 28, 2026
Becheler
left a comment
Collaborator
There was a problem hiding this comment.
Thank you so much @BayKeremm for this fix ! 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI disclosure: I used an AI assistant (Claude) to help write the tests, trace the cause and draft this text. I have checked the analysis and the fix myself and take responsibility for them.
Motivation
Fixes #655
When a vertex has more than one edge to the sink, the color map of
boykov_kolmogorov_max_flowis not a minimum cut, although the header says it is ("Use this if you are interested in the minimum cut, as the color map provides that info"). The flow returned is correct; a vertex the source still reaches is left gray. The issue has the details and a reproducer.What this PR does
Two commits
test:addstest_color_map_is_min_cut()totest/boykov_kolmogorov_max_flow_test.cpp, using the issue's two small graphs and no random ones. The first has two parallel edges to the sink; in the second, an edge out of the sink is followed by one into it. The test checks the flow, that vertex 1 is black, and that the cut the color map describes costs exactly the flow. Ondevelopthe flow is right but the other two checks fail in both graphs: 4 failures, so CI goes red.fix:adds one condition inaugment_direct_paths(): the loop over the sink's edges no longer moves a vertex that the loop over the source's edges has already put in the source tree. That vertex is active, sogrow()finds the path through its remaining edges to the sink. Before, the vertex was moved to the sink tree, left gray once those edges were saturated, and never reached again from the source, which is not an active vertex. CI goes green.The existing tests missed this because they compare flows, which were always right.
invariant_fourchecks that no residual edge crosses from one tree to another, but it skips the source, and the missing edge runs from the source to a gray vertex.Tested with g++ 16.2.1 and clang 23.1.3 (libstdc++), at
-std=c++14, 17, 20 and 23,-Wall -Wextra: no new warnings, andboykov_kolmogorov_max_flow_test,max_flow_testandmax_flow_algorithms_bundled_properties_and_named_paramspass. Separately, the color map with this fix was checked against brute force on 3,000 random networks of up to 10 vertices (every cut enumerated; parallel, reciprocal and zero-capacity edges, many ties) and against Edmonds-Karp on 320 larger ones. With the fix it was always a minimum cut, and on integer capacities exactly the smallest one.Before submitting
developbranch.Kind of change
Change category